<!DOCTYPE HTML>
<div id="form-grid">
<span class="page-heading">Add/Edit Offer</span>
	<div id="form-container">
	<?php
		//cal the sub category list
		$json = json_encode($sub_category);
		echo '<script type="text/javascript">
					var sub_categories = ' . $json . '; 
					var base_url="' . base_url() . '";
			  </script>';
			
		// Item Title
		echo form_open_multipart('offerform/'.$offer_info['offer_id'], array('id' => 'offer-form'));
		
		echo form_label("Title: ", "item_title", array('class' => 'normal-text'));
		$attribute = array(
			'name'		=> 'item_title',
			'id' 		=> 'item_title',
			'size' 		=> '75',
			'value' 	=> set_value('item_title',$offer_info['item_title']),
			'placeholder' => 'Your Item Title',
		);
		echo form_input($attribute) . '<br />';
		echo form_error('item_title');
		echo '<br />';
		
		// Item image upload
		echo '<div id="upload-image-container">';
		echo '<div class="the-image" id="image_preview"><img class="resize-200" src = "../resources/offer_images_thumbnail/' . $offer_info['item_pic'] .'" /></div>';
		echo '<span class="small-text"> Maximum file size is 3Mb. </span>';
		echo form_upload(array('name' => 'userfile', 'id' => 'userfile')) . '<br />';
		echo form_submit('upload_pic', 'Upload picture');
		if (isset($upload_file_error))
			echo '<br />' . $upload_file_error;
		echo '<input type="hidden" id="item_pic_name" name="item_pic_name" value="' . $offer_info['item_pic'] . '" />' ;
		echo '</div>';
		
		
		echo '<div id = "data-container">';
		// star rating system
		echo form_label("Condition of the item", "item_condition", array('class' => 'normal-text'));
		echo '<input type="hidden" id="item_condition" name="item_condition" value="' . set_value('item_condition',$offer_info['item_condition']) . '" />' ;
		echo '<div id = "star" class = "rate_widget">
				<div class="star_1 ratings_stars"></div>  
				<div class="star_2 ratings_stars"></div>  
				<div class="star_3 ratings_stars"></div>  
				<div class="star_4 ratings_stars"></div>  
				<div class="star_5 ratings_stars"></div>
				</div><br />';
			
		// Item Age
		echo form_label("Age:", "item_age", array('class' => 'normal-text')) ;
		echo '&nbsp&nbsp';
		// Item Age Year
		$option = array(
			'0'	=> '0',
			'1' => '1',
			'2'	=> '2',
			'3'	=> '3',
			'4' => '>3'
		);
		echo form_dropdown('age_year', $option, set_value('age_year',$offer_info['age_year']), 
									'class = "normal-text" id = "age_year" onChange="change_age_month_box()"');
		echo '&nbsp' . form_label('year', 'age_year', array('class' => 'normal-text', 'id' => 'age_year_label'));
		// Item Age Month
		echo '&nbsp&nbsp&nbsp';
		$option = array(
			'0'	=> '<1',
			'1' => '1',
			'2'	=> '2',
			'3'	=> '3',
			'4' => '4',
			'5' => '5',
			'6' => '6',
			'7' => '7',
			'8' => '8',
			'9' => '9',
			'10' => '10',
			'11' => '11'
		);
		echo form_dropdown('age_month', $option, set_value('age_month',$offer_info['age_month']),
									'class = "normal-text" id = "age_month" onChange="change_age_month_label()"');
		echo '&nbsp' . form_label('month', 'age_month', array('class' => 'normal-text', 'id' => 'age_month_label'));
		echo '<br />';
		
		// Item Category
		echo form_label('Category: ', 'category', array('class' => 'normal-text'));
		$this->load->model('offer_model');
		$option = array();
		foreach ($this->offer_model->get_category() as $cat) {
			$option[$cat['category_id']] = $cat['category_name'];
		}
		echo '<script type="text/javascript"> var sub_cat_id = ' . $offer_info['sub_category_id'] . '</script>';
		echo form_dropdown('category_id', $option, set_value('category_id',$offer_info['category_id']),
									'class="normal-text" id = "category_id" 
									onChange="change_sub_category_box()"');
		echo '<br />';
		
		// Item Sub Category
		echo form_label('Sub Category: ', 'sub_category', array('class' => 'normal-text'));
		$option = array();
		echo form_dropdown('sub_category_id', $option, $offer_info['sub_category_id'],
									'class = "normal-text" id = "sub_category_id"');		
		echo '<br />';							
		
		// Item Price
		echo form_label("Price (Select either Free or Cost): ", "price", array('class' => 'normal-text')). '<br />';
		if ($offer_info['item_price'] == 0) {
			echo "<input type='radio' id='price_free' name ='price_choice' value='0' " . set_radio('price_choice','0') . " onchange='change_price_box()' checked> Free </br>" ; 
			echo "<input type='radio' id='price_cost' name ='price_choice' value='1' " . set_radio('price_choice','1') . " onchange='change_price_box()'> Cost: $ ";
		} else {
			echo "<input type='radio' id='price_free' name ='price_choice' value='0' " . set_radio('price_choice','0') . " onchange='change_price_box()'> Free </br>" ; 
			echo "<input type='radio' id='price_cost' name ='price_choice' value='1' " . set_radio('price_choice','1') . " onchange='change_price_box()' checked> Cost: $ ";
		}
		//echo "<input type='number' id='item_price' name='item_price' value=" . $offer_info['item_price'] . " step='0.10' />";
		$attribute = array(
			'name'		=> 'item_price',
			'id' 		=> 'item_price',
			'size' 		=> '10',
			'value' 	=> set_value('item_price',$offer_info['item_price'])
		);
		echo form_input($attribute) . '<br />';
		echo form_error('item_price');
		echo '</div>';
		echo '<div style="clear:both"></div><br />';
		
		
		// Item description
		echo form_label("Description: ", "item_desc", array('class' => 'normal-text')) . '<br />';
		$attribute = array(
			'name'	=> 'item_desc',
			'id'	=> 'item_desc',
			'value' => set_value('item_desc',$offer_info['item_desc']),
			'placeholder' => 'A short Item Description',
		);
		echo form_textarea($attribute) . '<br />';
		echo form_error('item_desc');
		
		echo '<br />';
		//echo '<div id="submit-button"><input type="submit" src="'.base_url('/resources/offerform/submit.gif') .'" name="offer_submit"></div>';
		echo '<div id="submit-button"><input type="image" src="' .base_url("/resources/offerform/submit.gif") .'" name="offer_submit" alt="Submit" title="Submit"/></div>';
		echo form_close();
	?>
	</div>
</div>
<div style="height: 30px"></div>
